<%@ page language="Java" import="java.util.*,descriptor.*" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<%
	StudentDescriptor student = (StudentDescriptor)request.getAttribute("student");
	RecruiterDescriptor recruiter1 = (RecruiterDescriptor)request.getAttribute("recruiter");
	String error1 = "";
	if(recruiter1 == null){
		response.sendRedirect("index.jsp");
	}
	CVDescriptor cv = null;
	for (CVDescriptor cvFor : student.getCVs().getCVDescriptors()){
		if(cvFor.getPublishAuth()){
			cv= cvFor;
		}
	}

%>
<html>
	<jsp:include page="recruiterHeader.jsp" >
		<jsp:param name="pageTitle" value="Work Placement Management System - Recruiter" />
	</jsp:include>
	<body OnLoad="showmenu(document.getElementById('smenu2'));">
		<jsp:include page="recruiterPageHeader.jsp"></jsp:include>
		<div id="container">
			<jsp:include page="recruiterMenu.jsp" ></jsp:include>
			<div id="content">
			<h3 class="posttitle">Details about a student</h3>
				<div class="entry">
Name: <%=student.getFirstName()%> <%=student.getSurName()%><br/>
eMail : <%=student.getEmail()%> <br/>
<%if(cv == null){
%>
No CV Available<br/>
<%
}else{
%>
<a href="<%=cv.getFileLocation()%>">View CV</a><br/>
<%
}
%>

<%
TimetableListDescriptor tbList2 = student.getTimetableList();
TimetableListDescriptor tbList = student.getTimetableList();
%>

 							<div id="calendar" style="margin: 0;">
 								<form name="dateSelected" method="post">
 									<input type="hidden" name="action" value="dateSelected">
									<input type="hidden" id="day" name="day" value=""> 
									<input type="hidden" id="month" name="month" value="">   
									<input type="hidden" id="year" name="year" value=""> 
								</form> 
 								</div>
	 							<script type="text/javascript">
	 								var interviewDayArray =[<% if(tbList2 != null && tbList2.sizeTimetableList()>0)
															   	{
																	for(int i=0 ; i<tbList2.sizeTimetableList()-1 ; i++)
																	{ 
															%>
																<%= tbList2.getTimetableDescriptors().elementAt(i).getDay() %>,
															<%			
																	}
															%>		
																<%= tbList2.getTimetableDescriptors().elementAt(tbList2.sizeTimetableList()-1).getDay() %>
															<%	
																}
															%>
															]
									var interviewMonthArray = [<% if(tbList2 != null && tbList2.sizeTimetableList()>0)
															   {
																	for(int i=0 ; i<tbList2.sizeTimetableList()-1 ; i++)
																	{ 
															%>
																<%= tbList2.getTimetableDescriptors().elementAt(i).getMonth() %>,
															<%			
																	}
															%>		
																<%= tbList2.getTimetableDescriptors().elementAt(tbList2.sizeTimetableList()-1).getMonth() %>
															<%	
																}
															%>
															]
									var interviewYearArray = [<% if(tbList2 != null && tbList2.sizeTimetableList()>0)
															   {
																	for(int i=0 ; i<tbList2.sizeTimetableList()-1 ; i++)
																	{ 
															%>
																<%= tbList2.getTimetableDescriptors().elementAt(i).getYear() %>,
															<%			
																	}
															%>		
																<%= tbList2.getTimetableDescriptors().elementAt(tbList2.sizeTimetableList()-1).getYear() %>
															<%	
																}
															%>
															]
	     							function flatCalendarCallback(cal) 
	     							{
										if (cal.dateClicked) 
										{
											document.getElementById('day').value = cal.date.print("%e");
											document.getElementById('month').value = cal.date.print("%m");
											document.getElementById('year').value = cal.date.print("%Y");
											document.dateSelected.submit();
										}
									}
									
									function interview(dateValue)
	     							{
   										for(var i in interviewDayArray)
   										{
   											if(dateValue.getDate() == interviewDayArray[i])
   											{
   												if(dateValue.getMonth() == (interviewMonthArray[i]-1))
   												{
   													if(dateValue.getFullYear() == interviewYearArray[i])
   													{
   														return "special";
   													}
   												}
   											}
   										}
	     							}
	     							
	     							Zapatec.Calendar.setup(
	     							{
	        							firstDay          : 1,
	        							align 			  : "Bc",
	        							range             : [2008.01, 2999.12],
	        							electric          : false,
	       								flat 			  : "calendar",
	       								noCloseButton 	  : true,
	       								noHelp			  : true,
	       								weekNumbers       : false,
	       								inputField        : "dateSelected",
	       								dateStatusFunc 	  : interview,
	       								flatCallback 	  : flatCalendarCallback 
	      							}
	      							);
	   							</script>
 						
 						
 						
 						
 						
 											<%
						if(tbList != null)
						{
							int sizeList = tbList.sizeTimetableList();
							if(sizeList>0)
							{
								//TimetableListDescriptor tbList2 = tbList;
								int id = 0;
								String name1 = "";
								int day1 = 0;
								int month1 = 0;
								int year1 = 0;
								int hour1 = 0;
								int minute1 = 0;
								String recruiter = "";
								String offer = "";
								//int day2 = 0;
								//int month2 = 0;
								//int year2 = 0;
								//int hour2 = 0;
								//int minute2 = 0;
								for(int j=0; j<sizeList; j++)
								{
								//while(sizeList>0)
								//{
									
									//TimetableDescriptor tb = tbList2.getTimetableDescriptors().elementAt(j);
									id = tbList.getTimetableDescriptors().elementAt(j).getID();
									name1 = tbList.getTimetableDescriptors().elementAt(j).getName();
									day1 = tbList.getTimetableDescriptors().elementAt(j).getDay();
									month1 = tbList.getTimetableDescriptors().elementAt(j).getMonth();
									year1 = tbList.getTimetableDescriptors().elementAt(j).getYear();
									hour1 = tbList.getTimetableDescriptors().elementAt(j).getHour();
									minute1 = tbList.getTimetableDescriptors().elementAt(j).getMinute();
									recruiter = tbList.getTimetableDescriptors().elementAt(j).getRecruiterName();
									offer = tbList.getTimetableDescriptors().elementAt(j).getOfferName();
									String date1 = "";
									if(minute1 == 0)
									{	
										date1 = month1+"/"+day1+"/"+year1+ " " +hour1+":"+minute1+"0";
									}
									else
									{
										date1 = month1+"/"+day1+"/"+year1+ " " +hour1+":"+minute1;
									}
									
									//SimpleDateFormat df = new SimpleDateFormat("EEE, d MMM yyyy HH:mm");
									//df.setLenient(false);
									//Date dt1 = df.parse(date1);
									//GregorianCalendar calendar1 = new GregorianCalendar(); 
									//calendar1.setTime(dt1);
									//for(int i=0; i<sizeList; i++)
									//{
										//day2 = tbList.getTimetableDescriptors().elementAt(i).getDay();
										//month2 = tbList.getTimetableDescriptors().elementAt(i).getMonth();
										//year2 = tbList.getTimetableDescriptors().elementAt(i).getYear();
										//hour2 = tbList.getTimetableDescriptors().elementAt(i).getHour();
										//minute2 = tbList.getTimetableDescriptors().elementAt(i).getMinute();
										//String date2 = month2+"/"+day2+"/"+year2+ " " +hour2+":"+minute2;
										//Date dt2 = df.parse(date2);
										//GregorianCalendar calendar2 = new GregorianCalendar(); 
										//calendar2.setTime(dt2);
										//if(calendar1.compareTo(calendar2) == 1 )
										//{
											//tb = tbList2.getTimetableDescriptors().elementAt(j);
										//}
									//}*/
					%>
						<h4><%= date1 %></h4>
						<p> The student is busy </p>
						<br>
						<hr>
						<br>
					<% 
									//tbList2.deleteElt(tb);
									//j++;
								}
							}
						}
						else
						{
							if(error1 != null)
							{
					%>
								<p><%= error1 %></p>
								<form name="addEvent" method="post">
									<input type="hidden" name="action" value="addEvents">     
								</form> 
								<a href="javascript:document.addEvent.submit();" title="Add an event">Add an event</a>
					<%
							}
						}
					%>
<a href="RecruiterServlet?page=recuiterAddPersonalOffer&amp;studentId=<%=student.getId()%>">Make an offer</a>


				</div>
	    	</div>
			<jsp:include page="recruiterPageFooter.jsp"></jsp:include>
		</div>
	</body>
</html>